import { MockMethod } from 'vite-plugin-mock'
import { Api } from '~/api/demo'
import Mock, { Random } from 'mockjs'

export default [
  {
    url: '/home/data',
    // url: Api.Login,
    method: 'get',
    timeout: 200,
    statusCode: 200,
    response: () => {
      return {
        message: '',
        status: 200,
        data: Mock.mock({
          'banner|1-5': [{
            img: 'https://www.huoxingtv.net/attachment/images/global/yg2hu4Xru7eZM71pR6ME7HrsT456MV.png',
            // path: 'http://localhost:3000',
            path: Random.url('http', 'localhost:3000'),
            title: '火星传媒轮播',
            subtitle: '专业的PGC内容服务商',
            button: '',
          }],
          'adv|9-15': [{
            img: 'https://www.huoxingtv.net/attachment/images/global/sq658cy64FfcBOUUbBFCYy2BOfI6L2.png',
            // path: 'http://localhost:3000',
            path: Random.url('http', 'localhost:3000'),
            title: '视频直播',
            subtitle: '活动/赛事多机位传播',
            button: '',
          }],
        }),
      }
    },
  },
  {
    url: '/api/text',
    method: 'post',
    rawResponse: async (req, res) => {
      let reqbody = ''
      await new Promise((resolve) => {
        req.on('data', (chunk) => {
          reqbody += chunk
        })
        req.on('end', () => resolve(undefined))
      })
      res.setHeader('Content-Type', 'text/plain')
      res.statusCode = 200
      res.end(`hello, ${reqbody}`)
    },
  },
] as MockMethod[]
